#include "IApnDynamicArray.h"
#include <COMMDB.H>

CIApnDynamicArray::~CIApnDynamicArray()
	{
	iIAP.Close();
	}
void CIApnDynamicArray::CompleteConstructionL() {
	CAknEnumeratedTextPopupSettingItem::CompleteConstructionL();

	CArrayPtr<CAknEnumeratedText>* aEnumeratedTextArray = CAknEnumeratedTextPopupSettingItem::EnumeratedTextArray();
	//aEnumeratedTextArray->ResetAndDestroy();

	// open commdb
	CCommsDatabase* commDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
	CleanupStack::PushL(commDb);
	// open IAP table
	CCommsDbTableView* commView = commDb->OpenIAPTableViewMatchingBearerSetLC
	(ECommDbBearerCSD|ECommDbBearerGPRS,ECommDbConnectionDirectionOutgoing);
	// search all IAPs
	if (commView->GotoFirstRecord() == KErrNone)
		{
		TInt count = 1;
		do
			{
			TIAPClass aTempAPN;
			commView->ReadTextL(TPtrC(COMMDB_NAME),aTempAPN.iapName);
			commView->ReadUintL(TPtrC(COMMDB_ID),aTempAPN.iapId);
			
			HBufC* buf;
			buf = aTempAPN.iapName.AllocL();
			iIAP.Append(aTempAPN);
			CAknEnumeratedText *item = new (ELeave) CAknEnumeratedText(count,buf);
			aEnumeratedTextArray->AppendL(item);
			count++;
			}
		while (commView->GotoNextRecord() == KErrNone);
		}
	CleanupStack::PopAndDestroy(commView);
	CleanupStack::PopAndDestroy(commDb);
	
	HandleTextArrayUpdateL();
}
